
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
//framebuffer
#include <linux/fb.h>
//ioctl
#include <sys/ioctl.h>
//open file
# include<fcntl.h>
//mmap
#include <sys/mman.h>
//open file
#include <fstream>

using namespace std;

typedef unsigned char _uc;

FILE* fb;
_uc* fb_mem;
int fb_fd;
int maxx;
int maxy;

struct fb_var_screeninfo screen_var_info;

struct pixel {
    _uc B;
    _uc G;
    _uc R;
    _uc A;
};


int getInfo() {
    fb = fopen("/dev/fb0", "wb");
    fb_fd = open("/dev/fb0", O_RDWR);
    if (fb == NULL) {
        cout << "can't open framebuffer! check your kernel or try to exceute as root." << endl;
        return 0;
    }

    fclose(fb);
    ioctl(fb_fd, FBIOGET_VSCREENINFO, &screen_var_info);
    maxx = screen_var_info.xres;
    maxy = screen_var_info.yres;
    fb_mem = (_uc*)mmap(NULL, maxx * maxy * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);
    return 1;
}

inline void point(pixel px, int x, int y) {

    _uc* ptr = fb_mem + ((y - 1) * maxx + x) * 4;

    *ptr = px.B;
    ptr++;
    *ptr = px.G;
    ptr++;
    *ptr = px.R;
    ptr++;
    *ptr = px.A;
}
